package com.cuijq.ms.singleton.generator;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @Classname IdGenerator1
 * @Description 懒汉式
 * @Date 2021/5/5 9:42
 * @Created by CuiJQ
 */
public class IdGenerator1 {

  private AtomicLong id = new AtomicLong(0);
  private static IdGenerator1 instance;

  private IdGenerator1() {
  }

  public static synchronized IdGenerator1 getInstance() {
    if (instance == null) {
      instance = new IdGenerator1();
    }
    return instance;
  }

  public long getId() {
    return id.incrementAndGet();
  }
}
